<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class PassController extends Controller
{
    public function getDb()
    {
    //查询
        // $res = DB::select("select * from user");
    //插入数据
        //$res = DB::insert('insert into user(username,password,age,email) value ("erewr","345fdsf",34,"34354@qq.com")');

        //$res = DB::insert("insert into user(username,password,age) value (?,?,?)",['fff','3245',50]);
    //更新操作
        //$res = DB::update("update user set username=?,password=?,age=? where id =?",['nnnn','321435',56,4]);

    //删除数据
        //$res = DB::delete("delete from user where id = 4");
        //echo $res;

    //事务操作
        // DB::beginTransaction();
        // DB::update("update doller set money = money-500 where id= 5");
        // DB::update("update doller set money = money+500 where id =6");

        // DB::commit();

        // DB::rollback();

    //构造器
        //插入操作
        // DB::table('user')->insert([
        //     'username'=>'jjjj',
        //     'password'=>'234325',
        //     'age'=>90,
        //     'email'=>'ewrewr@163.com'
        //     ]);
        //插入多条数据
       /* DB::table('user')->insert(
            [
                [
                'username'=>'kkkk',
                'password'=>'3432',
                'age'=>56,
                'email'=>'21432453@qq.com'
                ],
                [
                'username'=>'ewew',
                'password'=>'3432',
                'age'=>56,
                'email'=>'21432453@qq.com'
                ],
                [
                'username'=>'mjhjyt',
                'password'=>'3432',
                'age'=>56,
                'email'=>'21432453@qq.com'
                ]
            ]);*/
        //获取最后插入的id
           // $res = DB::table('user')->insertGetId(
           //  [

           //      'username'=>'mjhjyt',
           //      'password'=>'3432',
           //      'age'=>56,
           //      'email'=>'21432453@qq.com'
                

           //  ]);

           // echo $res;

        //更新
            // DB::table('user')->where('id',7)->update([
            //     'username'=>'llll',
            //     'password'=>'2434',
            //     'age'=>67,
            //     'email'=>'jkjlj@sina.com'

            //     ]);
        //删除数据
            // DB::table('user')->where('id','<',5)->delete();

        //查询数据
        //查询所有
        // $res = DB::table('user')->get();
        //获取单条数据
        // $res = DB::table('user')->first();
        //获取单条数据里面的单一字段里面的值  
        //$res = DB::table('user')->value('username');
        //获取单列数据
       // $res = DB::table('user')->lists('username');

        //获取某些字段的值
       // $res = DB::table('user')->select('username','password')->get();



       // dd($res);
//
    // func();
    }
}
